<?php

/**
 * JS validator,Copyright (c) 2008 Arian Stolwijk, <http://aryweb.nl>, MIT Style License.
 * 
 * 
 * This is an example how you can use the js validator in combination with FH3.
 * Instead of creating an instance of Formhandler, you create an instance of the Fh3_JsValidator.
 * 
 * When the user submit the form when it isn't correct, PHP validates the field and prints errors
 * When the javascript validator validates the field, the PHP error must hide. In order to hide the
 * PHP error, you have to print the error in an <span> with id="error_[fieldname]". If you set another
 * rowmask with the setMask method, you can do that.
 * 
 */

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Javascript validator</title>

</head>
<body>


<?php 


// include the class 
include("fh3js.php"); 

// create a new FormHandler object 
$form = new Fh3_JsValidator(); 

$form->setMask(
  "  <tr>\n".
  "    <td valign='top' align='right'>%title%</td>\n".
  "    <td valign='top'>%seperator%</td>\n".
  "    <td valign='top'>%field% %help% <span id='error_%name%'>%error%</span></td>\n".
  "  </tr>\n"
);

// some fields.. (see manual for examples) 
$form->textField( "Name", "name", FH_STRING, 20, 40); 
$form->textField( "Age", "age", FH_INTEGER, 4, 40); 
$form->textField( "Functie", "functie", FH_STRING); 
$form->selectfield('Select','select',array('a',1,3,5,7),FH_DIGIT,false);
$form->textarea('text','text',FH_TEXT);
$form->textarea('text','text2',_FH_TEXT);
// button for submitting 
$form->submitButton(); 

// set the 'commit-after-form' function 
$form->onCorrect('doRun'); 

// display the form 
$form->flush(); 

// the 'commit-after-form' function 
function doRun( $data )  
{ 
    echo "Hello ". $data['name'].", you are ".$data['age'] ." years old!"; 
}


$form2 = new Fh3_JsValidator();

$form2->setMask(
  "  <tr>\n".
  "    <td valign='top' align='right'>%title%</td>\n".
  "    <td valign='top'>%seperator%</td>\n".
  "    <td valign='top'>%field% %help% <span id='error_%name%'>%error%</span></td>\n".
  "  </tr>\n"
);

// some fields.. (see manual for examples) 
$form2->textField( "Name", "name2", FH_STRING, 20, 40); 

$form2->onCorrect('doRun'); 

$form2->flush();

?>

</body>
</html>